package com.shoe.controller;

import com.shoe.pojo.AdminLogisticPojo;
import com.shoe.service.AdminLogisticService;
import com.shoe.util.ResultUtil;
import com.shoe.vo.AdminLogisticVo;
import com.shoe.vo.ResponseResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin")
@CrossOrigin
public class AdminLogisticController {

    @Autowired
    AdminLogisticService adminLogisticService;

    @Autowired
    ResultUtil resultUtil;

    @GetMapping("selealoglui")
    public ResponseResult selectALogLui(Integer page, Integer limit) {
        List<AdminLogisticVo> selectALogLuiPage = adminLogisticService.selALogLuiPage((page - 1) * limit, limit);
        List<AdminLogisticVo> selectALogLuiAll = adminLogisticService.selALogLuiAll();

        if (null != selectALogLuiPage && selectALogLuiPage.size() > 0) {
            return resultUtil.getResponseResult(0, "", selectALogLuiAll.size(), selectALogLuiPage);
        } else {
            return resultUtil.getResponseResult(2, "查询失败");
        }
    }

    @GetMapping("selectlogistic")
    public ResponseResult selectAdminLogisticAll(Integer page, Integer limit, String logisticLogisticnum, String orderState) {

        List<AdminLogisticVo> adminLogisticVoListAll = adminLogisticService.selectAdminLogisticByCondition(orderState);
        List<AdminLogisticVo> adminLogisticVoList = adminLogisticService.selectALogisticByCondPage((page - 1) * limit, limit, logisticLogisticnum, orderState);

        if (null != adminLogisticVoList && adminLogisticVoList.size() > 0) {
            return resultUtil.getResponseResult(0, "", adminLogisticVoListAll.size(), adminLogisticVoList);
        } else {
            return resultUtil.getResponseResult(2, "查询失败");
        }
    }

    @GetMapping("updateALog")
    public ResponseResult updateALogByCondition(AdminLogisticPojo adminLogisticPojo) {

        System.out.println("修改接收值" + adminLogisticPojo.toString());

        int affRow = adminLogisticService.updateALogByCondition(adminLogisticPojo);
        if (affRow > 0) {
            return resultUtil.getResponseResult(0, "操作成功");
        } else {
            return resultUtil.getResponseResult(2, "操作失败");
        }
    }

    @GetMapping("deletALogByLId")
    public ResponseResult deletALog(Integer aftSaleId) {
        int affRow = adminLogisticService.deletALogByLId(aftSaleId);
        if (affRow > 0) {
            return resultUtil.getResponseResult(0, "操作成功");
        } else {
            return resultUtil.getResponseResult(2, "操作失败");
        }
    }
}
